<template>
	<view class="point-record">
		<view class="board">
			<view class="stats-title">累计金数字资产</view>
			<view class="stats-value">{{total}}</view>
		</view>
		<view class="options">
			<view class="opts-type" @click="openOrderSelect">
				<view class="opt-text" v-if="order.order_no">订单号：{{order.order_no}}</view>
				<view class="opt-text" v-else>全部订单</view>
				<image class="icon32" :src="$util.img('/upload/uniapp/xxjk/bonusCenter/arrow_down_fill.png')" mode="">
				</image>
			</view>
			<date-range @change="changeDate"></date-range>
		</view>
		<mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback">
			<!-- 数据列表 -->
			<view class="list-box" v-if="dataList.length > 0">
				<view class="list-item" v-for="item in dataList">
					<view class="order-item-head">
						<view class="flex-between">
							<view class="order-no">订单号：{{item.order_no}}</view>
							<view class="order-type" :class="[item.type == 1?'blue':'']">{{item.type_name}}</view>
						</view>
						<view class="order-time">时间：{{item.creat_time}}</view>
					</view>
					<view class="order-item-stats">
						<view class="stats-item" v-for="fitem in statsField">
							<view class="stats-title">{{fitem.title}}</view>
							<view class="stats-value">{{item[fitem.value]}}</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else><ns-empty :isIndex="!1" :fixed="false" text="暂无数据"></ns-empty></view>
		</mescroll-body>
		<order-select ref="orderSelect" @change="changeOrder"></order-select>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll/mescroll-mixins.js";
	import orderSelect from './components/order-select';
	import dateRange from './components/date-range';
	export default {
		mixins: [MescrollMixin],
		components: {
			orderSelect,
			dateRange
		},
		data() {
			return {
				total: '',
				statsField: [{
					title: '消耗额度',
					value: 'bonus_amount'
				}, {
					title: '获得金数字资产',
					value: 'gold_points'
				}, {
					title: '获得x数字资产',
					value: 'x_value'
				}],
				listParams: {
					start: '',
					end: '',
					order_no: ''
				},
				order: {},
				dataList: []
			};
		},
		onLoad(options) {
			if (options.order_no) {
				this.order.order_no = options.order_no;
				this.listParams.order_no = options.order_no;
			}
		},
		methods: {
			openOrderSelect() {
				this.$refs.orderSelect.open()
			},
			changeOrder(e) {
				this.order = e.value;
				this.changeOptions({
					order_no: e.value.order_no
				});
			},
			changeDate(e) {
				this.changeOptions({
					start: e.value[0] || '',
					end: e.value[1] || ''
				})
			},
			upCallback(mescroll) {
				let url = ''
				this.$api.sendRequest({
					url: '/goldpoints/api/Record/goldPointsRecordList',
					data: {
						...this.listParams,
						page: mescroll.num,
						page_size: mescroll.size
					},
					success: (res) => {
						if (res.code == 0) {
							let {
								list,
								total
							} = res.data.list;

							this.total = total;

							list = list.map(item => {
								let type_name = ['订单生成', '团队加速', '直推', '平级奖励加速'][item.type]
								return {
									...item,
									type_name,
									creat_time: this.$util.timeStampTurnTime(item.creat_time)
								}
							});
							if (mescroll.num == 1) this.dataList = [];
							this.dataList = [...this.dataList, ...list];
							this.mescroll.endSuccess(this.dataList.length);
						} else {
							this.mescroll.endErr();
						}
					},
					fail: () => {
						this.mescroll.endErr();
					}
				})
			},
			changeOptions(data) {
				this.listParams = {
					...this.listParams,
					...data
				}
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0, 0);
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import './public/css/common.scss';

	view {
		box-sizing: border-box;
	}

	.flex-between {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.point-record {}

	.board {
		padding: 48rpx 30rpx;
		width: 750rpx;
		height: 220rpx;
		background: #FFF3F1;
		border-radius: 0rpx;

		.stats-title {
			font-size: 28rpx;
			color: #222222;
			line-height: 33rpx;
		}

		.stats-value {
			margin-top: 8rpx;
			font-family: Helvetica, Helvetica;
			font-weight: bold;
			font-size: 56rpx;
			color: #FC311A;
			line-height: 66rpx;
		}
	}

	.list-box {}

	.list-item {
		margin: 20rpx 24rpx;
		width: 702rpx;
		height: 268rpx;
		background: #FFFFFF;
		border-radius: 16rpx;

		.order-item-head {
			padding: 24rpx;
		}

		.order-no {
			font-weight: 400;
			font-size: 28rpx;
			color: #222222;
		}

		.order-type {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 128rpx;
			height: 46rpx;
			background: #FFF7E7;
			border-radius: 8rpx;
			font-weight: 400;
			font-size: 24rpx;
			color: #FCA600;

			&.blue {
				background-color: #E7F3FF;
				color: #459FF3;
			}
		}

		.order-time {
			margin-top: 8rpx;
			font-size: 24rpx;
			color: #999999;
			line-height: 28rpx;
		}

		.order-item-stats {
			display: flex;
			justify-content: space-around;
			align-items: center;
			border-top: 1rpx solid #EEEEEE;
			padding: 28rpx 0;

			.stats-item {
				.stats-title {
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 28rpx;
				}

				.stats-value {
					font-weight: 500;
					font-size: 28rpx;
					color: #222222;
					line-height: 33rpx;
				}
			}
		}
	}
</style>